﻿using SwenAssigment.Classes;
using SwenAssigment.DBClasses;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class ReportOccupancy : System.Web.UI.Page
    {
        public override void VerifyRenderingInServerForm(Control control)
        {

        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                int start = System.DateTime.Now.Year - 5;
                int end = System.DateTime.Now.Year + 5;
                for (int i = start; i <= end; i++)
                {
                    DropDownList1.Items.Add(i.ToString());
                }
            }
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Panel1.Visible = true;
            Label2.Text = DropDownList1.SelectedValue;
            OReport k = new OReport(Convert.ToInt32(DropDownList1.SelectedValue));
            ArrayList a = new ArrayList();
            ArrayList b = new ArrayList();
            ArrayList c = new ArrayList();
            //a.Add(k.GetAllMonthDate()[0].GetStatics());

            //a.Add(k.GetAllMonthDate()[1].GetStatics());
            foreach (Day d in k.GetYearAndDate().getDays())
            {
                a.Add(d.getDate().ToShortDateString() + " Statics: " + Math.Round(d.GetStatics(), 2).ToString() + "%");
            }
            Label1.Text = Math.Round(k.GetYearAndDate().GetStatics(), 2).ToString();
            GridView1.DataSource = a;
            GridView1.DataBind();
            //GridView1.Columns[-1].HeaderText = "All Dates: ";
            //GridView1.DataBind();
            foreach (Month d in k.GetAllMonthDate())
            {
                b.Add(d.getMonthName() + " Statics: " + Math.Round(d.GetStatics(), 2).ToString() + "% Date Range: " + d.getDays()[0].getDate().ToShortDateString() + " to " + d.getDays()[d.getDays().Count - 1].getDate().ToShortDateString());
            }
            GridView2.DataSource = b;
            GridView2.DataBind();
            foreach (Week d in k.GetAllWeek())
            {

                c.Add(d.getWeekNo().ToString() + " Statics: " + Math.Round(d.GetStatics(), 2).ToString() + "% Date Range: " + d.getDays()[0].getDate().ToShortDateString() + " to " + d.getDays()[d.getDays().Count - 1].getDate().ToShortDateString());
            }
            GridView3.DataSource = c;
            GridView3.DataBind();

            if (a == null)
            {
                Panel1.Visible = false;
            }

        }

        protected void Button4_Click(object sender, EventArgs e)
        {
            if (GridView1.Rows.Count > 0 && GridView2.Rows.Count > 0 && GridView3.Rows.Count > 0)
            {
                Response.Clear();
                Response.AddHeader("content-disposition", "attachment;filename=Avukat.xls");
                Response.Charset = "";

                Response.ContentType = "application/vnd.xls";
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                htmlWrite.AddAttribute(HtmlTextWriterAttribute.Class, "kk");
                htmlWrite.RenderBeginTag(HtmlTextWriterTag.Div);
                htmlWrite.Write("List of Days:");
                htmlWrite.RenderEndTag();
                GridView1.RenderControl(htmlWrite);
                htmlWrite.AddAttribute(HtmlTextWriterAttribute.Class, "kk");
                htmlWrite.RenderBeginTag(HtmlTextWriterTag.Div);
                htmlWrite.Write("List of Months:");
                htmlWrite.RenderEndTag();
                GridView2.RenderControl(htmlWrite);
                htmlWrite.AddAttribute(HtmlTextWriterAttribute.Class, "kk");
                htmlWrite.RenderBeginTag(HtmlTextWriterTag.Div);
                htmlWrite.Write("List of Weeks:");
                htmlWrite.RenderEndTag();
                GridView3.RenderControl(htmlWrite);
                htmlWrite.AddAttribute(HtmlTextWriterAttribute.Class, "kk");
                htmlWrite.RenderBeginTag(HtmlTextWriterTag.Div);
                htmlWrite.Write("The Statics for the Year is: " + Label1.Text + "%");
                htmlWrite.RenderEndTag();
                Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
                Response.Write(stringWrite.ToString());
                Response.End();
            }
        }
    }
}